package com.sugon.quartz;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @desc:
 * @author: luoy
 * @date: 2021-12-02 16:15
 */
public class TestHello {

    public static void main(String[] args) throws SchedulerException {

        //创建一个scheduler
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.getContext().put("skey", "svalue");

        //创建一个Trigger
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1)
                        .repeatForever()).build();
        trigger.getJobDataMap().put("num", "2");
        trigger.getJobDataMap().put("count", 0);

        //创建一个job
        JobDetail job = JobBuilder.newJob(HelloJob.class)
                //jobDataMap实为一个map
                .usingJobData("num", "1")
                .usingJobData("count", 0)
                .withIdentity("myjob", "mygroup").build();

        //注册trigger并启动scheduler
        scheduler.scheduleJob(job, trigger);
        scheduler.start();

    }
}